#include					"manualconnect.h"

ManualConnect::ManualConnect(QWidget *parent) : QDialog(parent)
{
}

ManualConnect::~ManualConnect() {}

void						ManualConnect::init()
{
	QVBoxLayout				*mainLayout = new QVBoxLayout();
	QVBoxLayout				*spaceLayout = new QVBoxLayout();
	QVBoxLayout				*labelLayout = new QVBoxLayout();
	QVBoxLayout				*lineLayout = new QVBoxLayout();
	QHBoxLayout				*allLayout = new QHBoxLayout();
	QHBoxLayout				*buttonLayout = new QHBoxLayout();
	QLabel					*ip = new QLabel("Ip");
	QLabel					*port = new QLabel("Port");
	
	_ipLine = new QLineEdit();
	_portLine = new QLineEdit();

	_connectButton = new QPushButton();
	_cancelButton = new QPushButton();
	

	_connectButton->setText("Connect to Server");
	_cancelButton->setText("Cancel");

	labelLayout->addWidget(ip);
	labelLayout->addWidget(port);

	lineLayout->addWidget(_ipLine);
	lineLayout->addWidget(_portLine);

	allLayout->addLayout(labelLayout);
	allLayout->addLayout(lineLayout);

	buttonLayout->addWidget(_connectButton);
	buttonLayout->addWidget(_cancelButton);

	spaceLayout->addLayout(allLayout);
	spaceLayout->addLayout(buttonLayout);

	mainLayout->addLayout(spaceLayout);

	setLayout(mainLayout);
	setWindowTitle("Manual Connection");
	setFixedSize(300, 100);
	connect(_cancelButton, SIGNAL(clicked()), this, SLOT(closeDialog()));
}

void						ManualConnect::closeEvent(QCloseEvent *event)
{
	event->ignore();
	hide();
}

const QString				ManualConnect::getIp() const
{
	return _ipLine->text();
}

const QString				ManualConnect::getPort() const
{
	return _portLine->text();
}

bool						ManualConnect::isInfoFilled()
{
	if (getIp().isEmpty() || getPort().isEmpty())
		return false;
	return true;
}

void						ManualConnect::closeDialog()
{
	close();
}